<?php


abstract class BaseTabDetallesOrden extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $cf_orden;


	
	protected $cf_servicio;


	
	protected $cf_subservicio;


	
	protected $cantidad;


	
	protected $cf_ente;


	
	protected $id;

	
	protected $aTabOrdenes;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getCfOrden()
	{

		return $this->cf_orden;
	}

	
	public function getCfServicio()
	{

		return $this->cf_servicio;
	}

	
	public function getCfSubservicio()
	{

		return $this->cf_subservicio;
	}

	
	public function getCantidad()
	{

		return $this->cantidad;
	}

	
	public function getCfEnte()
	{

		return $this->cf_ente;
	}

	
	public function getId()
	{

		return $this->id;
	}

	
	public function setCfOrden($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_orden !== $v) {
			$this->cf_orden = $v;
			$this->modifiedColumns[] = TabDetallesOrdenPeer::CF_ORDEN;
		}

		if ($this->aTabOrdenes !== null && $this->aTabOrdenes->getNumOrden() !== $v) {
			$this->aTabOrdenes = null;
		}

	} 
	
	public function setCfServicio($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_servicio !== $v) {
			$this->cf_servicio = $v;
			$this->modifiedColumns[] = TabDetallesOrdenPeer::CF_SERVICIO;
		}

	} 
	
	public function setCfSubservicio($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_subservicio !== $v) {
			$this->cf_subservicio = $v;
			$this->modifiedColumns[] = TabDetallesOrdenPeer::CF_SUBSERVICIO;
		}

	} 
	
	public function setCantidad($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->cantidad !== $v) {
			$this->cantidad = $v;
			$this->modifiedColumns[] = TabDetallesOrdenPeer::CANTIDAD;
		}

	} 
	
	public function setCfEnte($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->cf_ente !== $v) {
			$this->cf_ente = $v;
			$this->modifiedColumns[] = TabDetallesOrdenPeer::CF_ENTE;
		}

	} 
	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = TabDetallesOrdenPeer::ID;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->cf_orden = $rs->getString($startcol + 0);

			$this->cf_servicio = $rs->getString($startcol + 1);

			$this->cf_subservicio = $rs->getString($startcol + 2);

			$this->cantidad = $rs->getInt($startcol + 3);

			$this->cf_ente = $rs->getString($startcol + 4);

			$this->id = $rs->getInt($startcol + 5);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 6; 
		} catch (Exception $e) {
			throw new PropelException("Error populating TabDetallesOrden object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TabDetallesOrdenPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TabDetallesOrdenPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TabDetallesOrdenPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aTabOrdenes !== null) {
				if ($this->aTabOrdenes->isModified()) {
					$affectedRows += $this->aTabOrdenes->save($con);
				}
				$this->setTabOrdenes($this->aTabOrdenes);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TabDetallesOrdenPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TabDetallesOrdenPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aTabOrdenes !== null) {
				if (!$this->aTabOrdenes->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTabOrdenes->getValidationFailures());
				}
			}


			if (($retval = TabDetallesOrdenPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TabDetallesOrdenPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getCfOrden();
				break;
			case 1:
				return $this->getCfServicio();
				break;
			case 2:
				return $this->getCfSubservicio();
				break;
			case 3:
				return $this->getCantidad();
				break;
			case 4:
				return $this->getCfEnte();
				break;
			case 5:
				return $this->getId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TabDetallesOrdenPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getCfOrden(),
			$keys[1] => $this->getCfServicio(),
			$keys[2] => $this->getCfSubservicio(),
			$keys[3] => $this->getCantidad(),
			$keys[4] => $this->getCfEnte(),
			$keys[5] => $this->getId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TabDetallesOrdenPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setCfOrden($value);
				break;
			case 1:
				$this->setCfServicio($value);
				break;
			case 2:
				$this->setCfSubservicio($value);
				break;
			case 3:
				$this->setCantidad($value);
				break;
			case 4:
				$this->setCfEnte($value);
				break;
			case 5:
				$this->setId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TabDetallesOrdenPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setCfOrden($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setCfServicio($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setCfSubservicio($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setCantidad($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setCfEnte($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setId($arr[$keys[5]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TabDetallesOrdenPeer::DATABASE_NAME);

		if ($this->isColumnModified(TabDetallesOrdenPeer::CF_ORDEN)) $criteria->add(TabDetallesOrdenPeer::CF_ORDEN, $this->cf_orden);
		if ($this->isColumnModified(TabDetallesOrdenPeer::CF_SERVICIO)) $criteria->add(TabDetallesOrdenPeer::CF_SERVICIO, $this->cf_servicio);
		if ($this->isColumnModified(TabDetallesOrdenPeer::CF_SUBSERVICIO)) $criteria->add(TabDetallesOrdenPeer::CF_SUBSERVICIO, $this->cf_subservicio);
		if ($this->isColumnModified(TabDetallesOrdenPeer::CANTIDAD)) $criteria->add(TabDetallesOrdenPeer::CANTIDAD, $this->cantidad);
		if ($this->isColumnModified(TabDetallesOrdenPeer::CF_ENTE)) $criteria->add(TabDetallesOrdenPeer::CF_ENTE, $this->cf_ente);
		if ($this->isColumnModified(TabDetallesOrdenPeer::ID)) $criteria->add(TabDetallesOrdenPeer::ID, $this->id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TabDetallesOrdenPeer::DATABASE_NAME);

		$criteria->add(TabDetallesOrdenPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setCfOrden($this->cf_orden);

		$copyObj->setCfServicio($this->cf_servicio);

		$copyObj->setCfSubservicio($this->cf_subservicio);

		$copyObj->setCantidad($this->cantidad);

		$copyObj->setCfEnte($this->cf_ente);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TabDetallesOrdenPeer();
		}
		return self::$peer;
	}

	
	public function setTabOrdenes($v)
	{


		if ($v === null) {
			$this->setCfOrden(NULL);
		} else {
			$this->setCfOrden($v->getNumOrden());
		}


		$this->aTabOrdenes = $v;
	}


	
	public function getTabOrdenes($con = null)
	{
				include_once 'lib/model/om/BaseTabOrdenesPeer.php';

		if ($this->aTabOrdenes === null && (($this->cf_orden !== "" && $this->cf_orden !== null))) {

			$this->aTabOrdenes = TabOrdenesPeer::retrieveByPK($this->cf_orden, $con);

			
		}
		return $this->aTabOrdenes;
	}

} 